home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / ip / ka9q / src.arc / NRDUMP.C < prev    next >
C/C++ Source or Header  |  1989-08-12  |  3KB  |  117 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "netrom.h"
  5. #include "trace.h"
  6.  
  7. /* Display NET/ROM network and transport headers */
  8. void
  9. netrom_dump(bpp)
  10. struct mbuf **bpp;
  11. {
  12.     struct ax25_addr src,dest;
  13.     char x;
  14.     char tmp[16];
  15.     char thdr[5];
  16.     register i;
  17.  
  18.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  19.         return;
  20.     /* See if it is a routing broadcast */
  21.     if(uchar(*(*bpp)->data) == 0xff) {
  22.         pullup(bpp,tmp,1);        /* Signature */
  23.         pullup(bpp,tmp,ALEN);
  24.         tmp[ALEN] = '\0';
  25.         printf("NET/ROM Routing: %s\n",tmp);
  26.         for(i = 0;i < 11;i++) {
  27.             if (pullup(bpp,tmp,AXALEN) < AXALEN)
  28.                 break;
  29.             memcpy(src.call,tmp,ALEN);
  30.             src.ssid = tmp[ALEN];
  31.             pax25(tmp,&src);
  32.             printf("        %12s",tmp);
  33.             pullup(bpp,tmp,ALEN);
  34.             tmp[ALEN] = '\0';
  35.             printf("%8s",tmp);
  36.             pullup(bpp,tmp,AXALEN);
  37.             memcpy(src.call,tmp, ALEN);
  38.             src.ssid = tmp[ALEN];
  39.             pax25(tmp,&src);
  40.             printf("    %12s", tmp);
  41.             pullup(bpp,tmp,1);
  42.             printf("    %3u\n", uchar(tmp[0]));
  43.         }
  44.         return;
  45.     }
  46.     /* Decode network layer */
  47.     pullup(bpp,tmp,AXALEN);
  48.     memcpy(src.call,tmp,ALEN);
  49.     src.ssid = tmp[ALEN];
  50.     pax25(tmp,&src);
  51.     printf("NET/ROM: %s",tmp);
  52.  
  53.     pullup(bpp,tmp,AXALEN);
  54.     memcpy(dest.call,tmp,ALEN);
  55.     dest.ssid = tmp[ALEN];
  56.     pax25(tmp,&dest);
  57.     printf("->%s",tmp);
  58.  
  59.     pullup(bpp,&x,1);
  60.     printf(" ttl %d\n",uchar(x));
  61.  
  62.     /* Read first five bytes of "transport" header */
  63.     pullup(bpp,thdr,5);
  64.     switch(thdr[4] & 0xf){
  65.      case 0:    /* network PID extension */
  66.         if (thdr[0] == NRPROTO_IP && thdr[1] == NRPROTO_IP) {
  67.              ip_dump(bpp,1) ;
  68.             return;
  69.         }
  70.          else
  71.              printf("         protocol family %x, proto %x",
  72.                      uchar(thdr[0]), uchar(thdr[1])) ;
  73.          break ;
  74.     case 1:    /* Connect request */
  75.         printf("         conn rqst: ckt %d/%d",uchar(thdr[0]),uchar(thdr[1]));
  76.         pullup(bpp,&x,1);
  77.         printf(" wnd %d",x);
  78.         pullup(bpp,(char *)&src,AXALEN);
  79.         pax25(tmp,&src);
  80.         printf(" %s",tmp);
  81.         pullup(bpp,(char *)&dest,AXALEN);
  82.         pax25(tmp,&dest);
  83.         printf("@%s",tmp);
  84.         break;
  85.     case 2:    /* Connect acknowledgement */
  86.         printf("         conn ack: ur ckt %d/%d my ckt %d/%d",
  87.             uchar(thdr[0]), uchar(thdr[1]), uchar(thdr[2]),
  88.             uchar(thdr[3]));
  89.         pullup(bpp,&x,1);
  90.         printf(" wnd %d",x);
  91.         break;
  92.     case 3:    /* Disconnect request */
  93.         printf("         disc: ckt %d/%d",uchar(thdr[0]),uchar(thdr[1]));
  94.         break;
  95.     case 4:    /* Disconnect acknowledgement */
  96.         printf("         disc ack: ckt %d/%d",uchar(thdr[0]),uchar(thdr[1]));
  97.         break;
  98.     case 5:    /* Information (data) */
  99.         printf("         info: ckt %d/%d",uchar(thdr[0]),uchar(thdr[1]));
  100.         printf(" txseq %d rxseq %d",uchar(thdr[2]), uchar(thdr[3]));
  101.         break;
  102.     case 6:    /* Information acknowledgement */
  103.         printf("         info ack: ckt %d/%d",uchar(thdr[0]),uchar(thdr[1]));
  104.         printf(" txseq %d rxseq %d",uchar(thdr[2]), uchar(thdr[3]));
  105.         break;
  106.     default:
  107.          printf("         unknown transport type %d", thdr[4] & 0x0f) ;
  108.         break;
  109.     }
  110.     if(thdr[4] & 0x80)
  111.         printf(" CHOKE");
  112.     if(thdr[4] & 0x40)
  113.         printf(" NAK");
  114.     printf("\n");
  115. }
  116.  
  117.